#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    :  
# @function: 
# @version :


import asyncio


async def work():
    print('当前是一个协程任务...')
    await asyncio.sleep(1)
    return '返回值..'


async def main():
    # task_1 = asyncio.create_task(work())
    # task_2 = asyncio.create_task(work())
    #
    # # 获取返回值 gather
    # res = await asyncio.gather(task_1, task_2)
    # print(res)
    #
    # # 获取返回值 wait
    # done, pending = await asyncio.wait([task_1, task_2])
    # for res in done:
    #     print(res.result())

    # 获取返回值 as_completed
    coro_list = [work() for _ in range(2)]
    for coro in asyncio.as_completed(coro_list):  # as_completed返回的对象是一个迭代器
        # 谁先完成就先打印
        res = await coro
        print(res)


asyncio.run(main())
